<template>
	<view class="newDemand">
		<uni-forms ref="form" :modelValue="formData" :rules="rules">
			<uni-forms-item label="需求产品" name="name" required="true">
				<textarea type="textar" row="3" v-model="formData.name" placeholder="请输入需求产品"></textarea>
			</uni-forms-item>
			<uni-forms-item label="具体参数" name="email" required="true">
				<textarea  rows="3" v-model="formData.email" type="text" placeholder="请输入具体参数" ></textarea> 			
			</uni-forms-item>
			<uni-forms-item label="采购数量" name="email" >
				<uni-number-box :min="1" ></uni-number-box>
			</uni-forms-item>
			<uni-forms-item label="采购预算" name="email"  >
				<view @click="inputDialogToggle"  style="color: #999;">
					{{numbeVralue}}
				</view>
				<!-- <input type="text" placeholder="请选择" v-model="formData.email" style="padding-left:20rpx ;"> -->
			</uni-forms-item>
			<uni-forms-item label="供应商区域" name="email"  required="true">
				<text>请选择</text>
				<uni-icons type="right" size="30"  class="icon"></uni-icons>
			</uni-forms-item>
			<uni-forms-item label="添加标签" name="email"  required="true">
				<text>请选择</text>
				<uni-icons type="right" size="30" class="icon"></uni-icons>
			</uni-forms-item>
			<uni-forms-item label="是否公开电话" name="email"  >
				<uni-data-checkbox v-model="value" :localdata="range" @change="change"></uni-data-checkbox>
			</uni-forms-item>
			<uni-forms-item label="参考图片" name="email"  >
				<view class="label-right" style="position: absolute; left: 140rpx; top: -60rpx;  line-height: 30rpx; color: #A1A0A0; font-size: 30rpx;">（最多可上传4张图片）</view>
				<view class="img">
					<uni-file-picker
						v-model="imageValue" 
						fileMediatype="image" 
						@select="select" 
						@progress="progress" 
						@success="success" 
						@fail="fail" 
						limit="4"
						disable-preview
					/>
				</view>
			</uni-forms-item>
		</uni-forms>
		<view class="popup">
			<uni-popup ref="inputDialog" type="dialog">
				<uni-popup-dialog ref="inputClose"  mode="input" title="输入内容" value="对话框预置提示内容!"
					placeholder="请输入内容" @confirm="dialogInputConfirm"></uni-popup-dialog>
			</uni-popup>
		</view>
		<button class="forms-button" @click="submit">确定发布</button>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				formData: {
					name: '',
					email: ''
				},
				
				imageValue:[],
				numbeVralue:'请选择',
				value: 0,
				range: [{"value": 0,"text": "是"	},{"value": 1,"text": "否"}],
				rules: {
					// 对name字段进行必填验证
					name: {
						rules: [
							// 校验 不能为空
							{
								required: true,
								errorMessage: '不可为空',
							},
						]
					},
					// 对email字段进行必填验证
					email: {
						rules: [{
								required: true,
								errorMessage: '不可为空',
							},
						]
					},
				}
			}
		},
		methods:{
			submit() {
				this.$refs.form.validate(['id'],(err,formData)=>{
						if(!err){
							console.log('success',formData)
						}
					})
			
			},
			// 是否公开电话
			change(e){
					console.log('e:',e);
			},
			// 获取上传状态
			select(e){
				console.log('选择文件：',e)
			},
			// 获取上传进度
			progress(e){
				console.log('上传进度：',e)
			},
			
			// 上传成功
			success(e){
				console.log('上传成功')
			},
			
			// 上传失败
			fail(e){
				console.log('上传失败：',e)
			},
			// 模态框
			inputDialogToggle() {
				this.$refs.inputDialog.open()
			},
			// 模态框关闭
			dialogInputConfirm(val) {

				uni.hideLoading()
				console.log(val)
				this.value = val
				// 关闭窗口后，恢复默认内容
				this.$refs.inputDialog.close()
			},
		},
		onLoad(){
				this.formData.id = 'testId'
		},
		onShow(){
			
		}
	}
</script>

<style lang="scss" scoped>
	.newDemand::v-deep{
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		// forms
		.uni-forms{
			width: 100%;
			margin-bottom: 30rpx;
			// fomr-item
			.uni-forms-item{
				width: 100%;
				display: flex;
				flex-wrap: wrap;
				margin-bottom: 0;
				margin: 30rpx 0;
				.uni-forms-item__label{
					width: 100%; 
					color: #000;
					padding-right: 0;
					position: relative;
					font-size: 35rpx;
					.is-required{
						position:absolute;
						right: 0rpx;
						top: 20rpx;
					}
				}
				.uni-forms-item__content{
					width: 100%;
					border-radius: 10rpx;
					margin-top: 10rpx;
					// box-sizing: border-box;
					background-color: #fff;
					textarea{
						height: 120rpx;
						width: 650rpx;
					}
					.icon{
						margin-left: 5rpx;
						font-size: 30rpx;
					}
					
				}
			}
			
			.uni-forms-item:nth-child(1){
				margin-top: 0;
				.uni-forms-item__content{
					background-color: #F7F7F7;
					padding:  20rpx;
				}
				.is-required{
					right: -20rpx;
				}
				
			}
			.uni-forms-item:nth-child(2){
				.uni-forms-item__content{
					background-color: #F7F7F7;
					padding:  20rpx;
				}
				.is-required{
					right: -20rpx;
				}
				
			}
			.uni-forms-item:nth-child(6),
			.uni-forms-item:nth-child(5),
			.uni-forms-item:nth-child(4),
			.uni-forms-item:nth-child(3){
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 0;
				border-bottom: 1rpx solid rgba(0,0,0,.1);
				font-weight: 1;
				.uni-forms-item__label{
					width: 50%;
				}
				.uni-forms-item__content{
					width: 50%;
					text-align: right;
					
					
				}
			}
			.uni-forms-item:nth-child(3){
				.uni-forms-item__content{
					.data-v-037cdca0{
						float: right;
						
					}
					
				}
			}
			.uni-forms-item:nth-child(6){
				.uni-forms-item__label{
					width: 30% !important;
					
				}
				.is-required{
					position:absolute;
					right: 50rpx;
				}
			}
			.uni-forms-item:nth-child(5){
				.uni-forms-item__label{
					width: 50% !important ;
				}
				.is-required{
					position:absolute;
					right: 150rpx;
				}
			}
			.uni-forms-item:nth-child(8),
			.uni-forms-item:nth-child(7){
				.uni-forms-item__label{
					width: 100% !important ;
				}
			}
			.uni-forms-item:nth-child(8){

				.uni-forms-item__content{
					position: relative;
					.img{
						width: 690rpx;
						height: 100%;
						.uni-file-picker{
							width: 100%;
							height:100%;
							.file-picker__box-content{
								width: 200rpx;
								height: 200rpx;
							}
						}
					}
					
				}
			}
		}
		.forms-button{
			width: 100%;
			border-radius: 50rpx;
			background-image: linear-gradient(#54D6D2,#00AAA6);
			color: #fff;
			font-size: 40rpx;
			text-align: center;
			box-sizing: border-box;
			margin-top: 30rpx;
		}
	}
</style>